﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace UtilLib.OS
{
	/// <summary>
	/// 控制显示器开启、关闭
	/// </summary>
	/// <see cref="http://www.cnblogs.com/TianFang/archive/2010/12/25/1916874.html"/>
	public static class Monitor
	{
		public static void Off()
		{
			ChangeMonitorState(MonitorMode.OFF);
		}

		public static void On()
		{
			ChangeMonitorState(MonitorMode.ON);
		}

		public static void StandBy()
		{
			ChangeMonitorState(MonitorMode.STANBY);
		}

		#region WinAPI

		[DllImport("user32.dll")]
		static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);

		const int SC_MONITORPOWER = 0xF170;
		const int WM_SYSCOMMAND = 0x0112;

		enum MonitorMode : int
		{
			ON = -1,
			STANBY = 1,
			OFF = 2,
		}

		static void ChangeMonitorState(MonitorMode mode)
		{
			SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, (int)mode);
		} 

		#endregion
	}
}
